<template>
    <div class="menuWrap">
        <transition name="menuLeft">
            <div v-show="showMenu" class="menu">
                <div @click="curToUserProfile" class="avatar">
                    <div class="m-avatar">
                        <img :src="userInfo.avatar_url" alt="">
                    </div>
                    <div class="text">
                        {{userInfo.loginname}}
                    </div>
                    <div class="triangle">
                    </div>
                </div>
                <div class="solid"></div>
                <ul class="list">
                    <li @click="toList('all')" :class="selectedClass('all')">
                        <i class="fa fa-bars" aria-hidden="true"></i>
                        全部
                    </li>
                    <li @click="toList('good')" :class="selectedClass('good')">
                        <i class="fa fa-thumbs-up" aria-hidden="true"></i>
                        精华
                    </li>
                    <li @click="toList('share')" :class="selectedClass('share')">
                        <i class="fa fa-share-alt" aria-hidden="true"></i>
                        分享
                    </li>
                    <li @click="toList('ask')" :class="selectedClass('ask')">
                        <i class="fa fa-comments-o" aria-hidden="true"></i>
                        问答
                    </li>
                    <li @click="toList('job')" :class="selectedClass('job')">
                        <i class="fa fa-users" aria-hidden="true"></i>
                        招聘
                    </li>
                </ul>
                <div class="solid"></div>
                <ul class="list">
                    <li @click="mToPage('message')">
                        <i class="fa fa-bell-o" aria-hidden="true"></i>
                        消息
                    </li>
                    <li @click="mToPage('abot')">
                        <i class="fa fa-info-circle" aria-hidden="true"></i>
                        关于
                    </li>
                    <li @click="mToPage('setting')">
                        <i class="fa fa-cog" aria-hidden="true"></i>
                        设置
                    </li>
                </ul>
            </div>
        </transition>
        <div v-if="showMenu" @click="hideMenu" class="cover"></div>
    </div>
</template>
<script>
import * as API from '../api'

export default {
    name: 'menu',
    props: {},

    data() {
        return {
        }
    },

    created() {
        var tthis = this;
    },

    computed: {
       
        showMenu() {
            // console.log(this.$store.state.menu.status.show)
            return this.$store.state.menu.status.show;
        },
        userInfo() {
            return this.$store.state.user.userInfo;
        }

    },

    activated() {},

    methods: {
        selectedClass(name){
            if(this.$route.name == 'topics'){
                var queryTab = this.$route.query.tab || 'all';
                // console.log(queryTab)
                if(queryTab == name){
                    return 'g-bg selected';
                }
            }
        },
        mToPage(name){
            this.hideMenu();
            this.toPage(name);
        },
        toList(tab) {
            this.hideMenu();
            this.$router.push({
                name: 'topics',
                query: { tab: tab }
            })
        },
        curToUserProfile(){
            this.hideMenu();
            this.toUserProfile();
        },
        hideMenu() {
            this.$store.commit('setMenuShow', false);
        }
    }
}

</script>
<style lang="less" scoped>
@pdLR :16px;

.menuLeft-enter-active {
    transform: translateX(-180px);
}

.menuLeft-enter-to {
    transition: all .3s ease;
    transform: translateX(0px);
}

.menuLeft-leave-active {
    transition: all .3s ease;
    transform: translateX(-180px);
}


.cover {
    position: fixed;
    z-index: 8;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, .5);
}

.menu {
    position: fixed;
    z-index: 9;
    left: 0;
    top: 0;
    width: 180px;
    height: 100%;
    box-shadow: 0px 0px 8px #757575;
    background: #fff;
}

.solid{
    width: 80%;
    margin: 0 10%;
    height: 1px;
    margin-bottom: 10px;
    background: #f2f2f2;
}

.list {
    padding-bottom: 10px;
    li {
        @liHeight: 40px;
        padding: 10px 30px;
        display: block;
        .fa{
            float: left;
            font-size: 16px;
            margin-top: 1px;
            min-width: 36px;
        }
        a {
            display: block;
        }
        &:active {
            background: #f3f3f3;
        }
    }
    &:last-child{
        margin-top: 15px;
    }
}

.avatar {
    @avaterHeight: 42px;
    padding: 20px @pdLR;
    display: flex;
    .m-avatar {
        min-width: @avaterHeight;
        width: @avaterHeight;
        height: @avaterHeight;
        font-size: @avaterHeight;
    }
    .text {
        height: 42px;
        padding: 0 10px;
        line-height: @avaterHeight - 2px;
        flex: 1;
        font-weight: 600;
        color: #444;
    }
    .triangle {
        position: relative;
        height: @avaterHeight;
        &::after,
        &::before {
            @triangleSize: 7px;
            content: '';
            position: absolute;
            right: 0;
            top: 13px;
            width: 0;
            height: 0;
            border-top: @triangleSize solid transparent;
            border-bottom: @triangleSize solid transparent;
            border-left: @triangleSize solid #d4d4d4;
        }
        &::after {
            right: 2px;
            border-left-color: #fff;
        }
    }
}

</style>
